package hello.word.m2.maven.jpa.support;

import hello.word.m2.maven.jpa.BindJpql;
import hello.word.m2.maven.jpa.Jpqls;
import org.jdbi.v3.core.config.ConfigRegistry;
import org.jdbi.v3.sqlobject.locator.AnnotationSqlLocator;

import java.lang.reflect.Method;
import java.util.Objects;

public class CustomizedAnnotationSqlLocator extends AnnotationSqlLocator {
	
	@Override
	public String locate(Class<?> sqlObjectType, Method method, ConfigRegistry config) {
		
		if(Objects.nonNull(method.getAnnotation(BindJpql.class))) {
			Jpqls jpqls = config.get(Jpqls.class);
			return jpqls.getJpqlBuilder().build(sqlObjectType, method, config);
		}
		
		return super.locate(sqlObjectType, method, config);
	}
	
}